using System;
using System.Collections.Generic;
using System.Linq;

namespace LambdaExpressionExample // 命名空间
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // 创建一个整数列表
            List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // 使用 Lambda 表达式过滤出偶数
            var evenNumbers = numbers.Where(n => n % 2 == 0).ToList();

            Console.WriteLine("Even Numbers:");
            foreach (var number in evenNumbers)
            {
                Console.WriteLine(number);
            }

            // 使用 Lambda 表达式计算每个数字的平方
            var squaredNumbers = numbers.Select(n => n * n).ToList();

            Console.WriteLine("\nSquared Numbers:");
            foreach (var squared in squaredNumbers)
            {
                Console.WriteLine(squared);
            }

            // 使用 Lambda 表达式查找某个数字
            int searchNumber = 5;
            bool containsNumber = numbers.Any(n => n == searchNumber);
            Console.WriteLine($"\nList contains {searchNumber}: {containsNumber}");

            // 使用 Lambda 表达式进行求和
            int sum = numbers.Sum(n => n);
            Console.WriteLine($"\nSum of all numbers: {sum}");
        }
    }
}
